package com.eqdd.yiqidian.kotlin

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.eqdd.yiqidian.adapter.listadapter.QuickAdapter

/**
 * Created by jhj on 18-6-23.
 */
abstract class BaseRecyclerViewAdapter<T> : RecyclerView.Adapter<BaseRecyclerViewAdapter.ItemViewHolder>() {

    var dataList: ArrayList<T> = arrayListOf()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
        val inflater = LayoutInflater.from(parent.context)
        val view = onCreateView(viewType)
        return ItemViewHolder(inflater.inflate(view, parent, false))
    }


    override fun getItemCount(): Int {
        return dataList.size
    }

    override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
        holder.itemView.tag = dataList[position]
        onBindViewItemViewHolder(holder, dataList[position], position)
    }

    abstract fun onCreateView(viewType: Int): Int

    abstract fun onBindViewItemViewHolder(holder: BaseRecyclerViewAdapter.ItemViewHolder, bean: T, position: Int)


    class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}